/*
 * @Description: 
 * @Author: ouyaping
 * @Date: 2023-04-11 14:38:34
 * @LastEditors: ouyaping
 * @LastEditTime: 2023-04-14 12:34:32
 */
import { Injectable } from '@nestjs/common';
import { Client, ClientGrpc, GrpcOptions, Transport } from '@nestjs/microservices';
import { join } from 'path';

@Injectable()
export class GrpcClientFactory {

    @Client(generateGrpcOptions('192.168.0.119:50052', 'VA600Algorithm', 'algorithm.proto'))
    public readonly userServiceClient: ClientGrpc;
}

export function generateGrpcOptions(url: string, packageName: string, protoFileName: string): GrpcOptions {
    return {
        transport: Transport.GRPC,
        options: {
            url,
            package: packageName,
            protoPath: join(__dirname, '../protobufs/' + protoFileName),
            loader: {
                arrays: true
            }
        }
    };
}